package cn.edu.hstc.wm.adapter;

import java.util.List;

import cn.edu.hstc.wm.R;
import cn.edu.hstc.wm.bean.Comment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 店铺页面显示用户评论适配器
 * 
 */
public class StoreCommentAdapter extends BaseAdapter {

	public static final String TAG = "StoreCommentAdapter";

	private Context mContext;
	private List<Comment> comments;

	public StoreCommentAdapter(Context context, List<Comment> list) {
		this.mContext = context;
		this.comments = list;
	}

	@Override
	public int getCount() {
		return comments.size();
	}

	@Override
	public Object getItem(int position) {
		return comments.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.store_comment_item, null);
			holder = new ViewHolder();
			holder.userName = (TextView) convertView.findViewById(R.id.tv_store_comment_item_username);
			holder.time = (TextView) convertView.findViewById(R.id.tv_store_comment_item_time);
			holder.content = (TextView) convertView.findViewById(R.id.tv_store_comment_item_content);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.userName.setText(comments.get(position).getUserName());
		holder.time.setText(comments.get(position).getTime());
		holder.content.setText(comments.get(position).getComment());

		return convertView;
	}

	private final class ViewHolder {
		TextView userName, time, content;
	}
}
